<?php

class LogoutController extends Controller_Action
{
	public function indexAction()
	{
		$this->_disableView();
		$this->terminateOrder('chat');
		Auth::getInstance()->onLogout();
		$this->_redirect('/');
	}
	
	/**
	 * завершить заказ
	 * @param string $orderType
	 */
	public function terminateOrder($orderType) {
		$user = $this->_getUser();
		if ($user) {
			switch($orderType) {
				case 'chat':
					$chatService = ChatService::getInstance();
					//$chatService = new ChatService();
					$chatCostRow = $chatService->getCurrentUserChat($user);

					if ($chatCostRow) {
						$pushService = PushService::getInstance();
						$otherUser = $chatService->terminate($chatCostRow);
						
						$partnerMessage = ErrorMessages::getErrorMsg('chat', 301);
						$pushService->initPushId($otherUser);
						$pushService->push(PushService::MODULE_CHAT, 'terminated', $partnerMessage, time(), PushService::STATUS_OK);
					}
					break;
				default:
			}
		}
	}
}